@echo off
echo Generating icon resource file...

cd /d "%~dp0\.."

:: 清理旧文件
if exist "rsrc.syso" del "rsrc.syso"
if exist "rsrc.go" del "rsrc.go"
if exist "app.rc" del "app.rc"

:: 创建简单的资源脚本
echo IDI_ICON1 ICON "assets/app.ico" > app.rc

:: 尝试使用windres
windres --version >nul 2>&1
if not errorlevel 1 (
    echo Using windres to compile resource...
    windres -o rsrc.syso app.rc
    if not errorlevel 1 (
        echo OK: Resource file generated with windres
        del app.rc
        exit /b 0
    )
)

:: 尝试使用goversioninfo
echo Trying goversioninfo...
go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo
if not errorlevel 1 (
    :: 创建versioninfo.json
    echo { > versioninfo.json
    echo   "FixedFileInfo": { >> versioninfo.json
    echo     "FileVersion": { >> versioninfo.json
    echo       "Major": 1, >> versioninfo.json
    echo       "Minor": 0, >> versioninfo.json
    echo       "Patch": 0, >> versioninfo.json
    echo       "Build": 0 >> versioninfo.json
    echo     }, >> versioninfo.json
    echo     "ProductVersion": { >> versioninfo.json
    echo       "Major": 1, >> versioninfo.json
    echo       "Minor": 0, >> versioninfo.json
    echo       "Patch": 0, >> versioninfo.json
    echo       "Build": 0 >> versioninfo.json
    echo     }, >> versioninfo.json
    echo     "FileFlagsMask": "3f", >> versioninfo.json
    echo     "FileFlags ": "00", >> versioninfo.json
    echo     "FileOS": "040004", >> versioninfo.json
    echo     "FileType": "01", >> versioninfo.json
    echo     "FileSubType": "00" >> versioninfo.json
    echo   }, >> versioninfo.json
    echo   "StringFileInfo": { >> versioninfo.json
    echo     "Comments": "", >> versioninfo.json
    echo     "CompanyName": "FileHive", >> versioninfo.json
    echo     "FileDescription": "FileHive - File sharing application", >> versioninfo.json
    echo     "FileVersion": "1.0.0.0", >> versioninfo.json
    echo     "InternalName": "filehive", >> versioninfo.json
    echo     "LegalCopyright": "", >> versioninfo.json
    echo     "LegalTrademarks": "", >> versioninfo.json
    echo     "OriginalFilename": "filehive.exe", >> versioninfo.json
    echo     "PrivateBuild": "", >> versioninfo.json
    echo     "ProductName": "FileHive", >> versioninfo.json
    echo     "ProductVersion": "1.0.0.0", >> versioninfo.json
    echo     "SpecialBuild": "" >> versioninfo.json
    echo   }, >> versioninfo.json
    echo   "VarFileInfo": { >> versioninfo.json
    echo     "Translation": { >> versioninfo.json
    echo       "LangID": "0409", >> versioninfo.json
    echo       "CharsetID": "04B0" >> versioninfo.json
    echo     } >> versioninfo.json
    echo   }, >> versioninfo.json
    echo   "IconPath": "assets/app.ico", >> versioninfo.json
    echo   "ManifestPath": "" >> versioninfo.json
    echo } >> versioninfo.json
    
    goversioninfo -o rsrc.syso
    if not errorlevel 1 (
        echo OK: Resource file generated with goversioninfo
        del versioninfo.json
        del app.rc
        exit /b 0
    )
)

echo Failed to generate icon resource file
del app.rc
exit /b 1 